package org.bw.bookstore.book.controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.bw.bookstore.book.service.ShoppingCartService;
import org.bw.bookstore.common.entity.TbShoppingRecord;
import org.bw.bookstore.common.utils.ResponseResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;


/**
 * @Description:购物车
 * @Author: 钟乐
 * @Date: 2020/10/22 11:51
 **/

@RestController
@CrossOrigin
@Slf4j
@RequestMapping("shoppingCart")
@Api(tags = "接口-购物车管理微服务")
public class ShoppingCartController {

    @Autowired
    private ShoppingCartService shoppingCartService;

    /**
     * TODO 钟乐 加入购物车
     * @Author: 钟乐
     * @return: com.bw.wisdom_bookstore.entity.ResponseResult
     **/
    @PostMapping("joinShoppingCart")
    @ApiOperation(value="加入购物车", notes="加入购物车")
    @ApiImplicitParams(value = {
            @ApiImplicitParam(name = "userInfoCode", value = "用户code",dataType = "String",required = true),
            @ApiImplicitParam(name = "bookDetailedCode", value = "图书code",dataType = "String",required = true),
            @ApiImplicitParam(name = "bookNum", value = "图书数量",dataType = "Integer",required = true)
    })
    public ResponseResult joinShoppingCart(@ApiIgnore TbShoppingRecord tbShoppingRecord){
        return shoppingCartService.joinShoppingCart(tbShoppingRecord);
    }


    /**
     * TODO 钟乐 根据用户code查找购物车记录
     * @Author: 钟乐
     * @Date: 2020/10/21 19:29
     * @return: com.bw.common.utils.ResponseResult
     **/
    @PostMapping("showShoppingCart")
    @ApiOperation(value="查看购物车", notes="查看购物车")
    @ApiImplicitParams(value = {
            @ApiImplicitParam(name = "userInfoCode", value = "用户code",dataType = "String",required = true)
    })
    public ResponseResult showShoppingCart(@RequestParam("userInfoCode") String userInfoCode){
        return shoppingCartService.showShoppingCart(userInfoCode);
    }


    /**
    　　* TODO  findShoppingRecordByCode--根据商品code查找数据
    　　* @Param [userInfoCode, bookDetailedCode]
    　　* @return com.bw.common.utils.ResponseResult
    　　* @author 钟乐
    　　* @date 2020/10/24 15:48
    　　*/
    @PostMapping("findShoppingRecordByCode")
    @ApiOperation(value="根据商品code查找数据", notes="根据商品code查找数据")
    @ApiImplicitParams(value = {
            @ApiImplicitParam(name = "userInfoCode", value = "用户code",dataType = "String",required = true),
            @ApiImplicitParam(name = "bookDetailedCode", value = "书籍code",dataType = "String",required = true)
    })
    public ResponseResult findShoppingRecordByCode(@RequestParam("userInfoCode") String userInfoCode,
                                           @RequestParam("bookDetailedCode") String bookDetailedCode){
        return shoppingCartService.findShoppingRecordByCode(userInfoCode,bookDetailedCode);
    }

    /**
     * TODO 钟乐 取消购物车商品
     * @Author: 钟乐
     * @Date: 2020/10/21 19:50
     * @param shoppingCartId: 购物车id
     * @return: com.bw.common.utils.ResponseResult
     **/
    @PostMapping("delShoppingCart")
    @ApiOperation(value="取消购物车商品", notes="取消购物车商品")
    @ApiImplicitParams(value = {
            @ApiImplicitParam(name = "shoppingCartId", value = "购物车记录id",dataType = "String",required = true)
    })
    public ResponseResult delShoppingCart(@RequestParam("shoppingCartId")String shoppingCartId){
        return shoppingCartService.delShoppingCart(shoppingCartId);
    }


}
